﻿@using Apps.Models.Sys;
@using Apps.Common;
@using Apps.Web.Core;

@model Apps.Models.Sys.RoleUserInfoModel

@{
    ViewBag.Title = "Allot";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<PermModel> perm = ViewBag.perm;
    if (perm == null)
    {
        perm = new List<PermModel>();
    }
}
<script src="@Url.Content("~/Scripts/jquery.easyui.plus.js")" type="text/javascript"></script>
<div class="mvctool bgb">
    @Html.ToolButton("btnSave","icon-save","保存",true,perm,"Save")
</div>
<table id="RoleList"></table>

<script type="text/javascript">
    $(function () {
        $('#RoleList').datagrid({
            url: '@Url.Action("GetUserByRoleId")?id=' + '@ViewBag.roleId',
            method: 'post',
            width: $(window).width() - 10,
            height: $(window).height() - 35,
            fitColumns: true,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 10,
            pageList: [10, 20, 30, 40, 50],
            pagination: true,
            striped: true,
            singleSelect: true,
            columns: [[
                { field: 'Id', title: 'ID', width: 80, hidden: true },
                { field: 'UserName', title: '用户名', width: 80 },
                { field: 'TrueName', title: '姓名', width: 80 },
                {
                    field: 'Flag', title: '是否分配', width: 80, formatter: function (value) {
                        if (value != "0") {
                            return "<input type='checkbox' checked=true value='true'/>";
                        } else {
                            return "<input type='checkbox'  value='false'/>";
                        }
                    }
                }
            ]]
        });
    });
</script>
<script type="text/javascript">
    $(function () {
        $('#btnSave').click(function () {
            var rows = $('#RoleList').datagrid('getRows');
            var data = new Array();
            for (var i = 0; i < rows.length; i++) {
                var setFlag = $("td[field='Flag'] input").eq(i).prop('checked');
                if (setFlag) {
                    data.push(rows[i].Id);
                    alert(setFlag);
                }
            }
            var userIds = data.join();
            $.post("/SysRole/UpdateSysRoleSysUser", { roleId: '@ViewBag.roleId', userIds: userIds }, function (data) {
                if (data.tag == 1) {
                    window.parent.frameReturnByMes(data.message);
                    window.parent.frameReturnByReload(true);
                    window.parent.frameReturnByClose();
                } else {
                    window.parent.frameReturnByMes(data.message);
                }
            }, 'json');
        });
    });
</script>

